package cn.tl.org.controller;

import cn.tl.org.domain.Employee;
import cn.tl.org.domain.Shop;
import cn.tl.org.query.EmployeeQuery;
import cn.tl.org.query.ShopQuery;
import cn.tl.org.service.IEmployeeService;
import cn.tl.org.service.IShopService;
import cn.tl.org.utils.AjaxResult;
import cn.tl.org.utils.QueryResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shop")
@Api(tags = "商店维护")
//@CrossOrigin
public class ShopController {
    @Autowired
    private IShopService shopService;
    @PutMapping
    @ApiOperation(value = "新增或修改接口")
    public AjaxResult saveOrUpt(@RequestBody Shop shop){
        try {
            if (shop.getId() == null){
                shopService.save(shop);
            }else {
                shopService.update(shop);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }

    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            shopService.delete(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }

    @GetMapping("/{id}")
    public Shop findById(@PathVariable("id") Long id){
        return shopService.findById(id);
    }
    @GetMapping
    public List<Shop> findAll(){
        return shopService.findAll();
    }

    @PostMapping
    public QueryResult<Shop> queryPage(@RequestBody ShopQuery shopQuery){
        return shopService.queryPage(shopQuery);
    }

    @PatchMapping
    public AjaxResult patchDel(@RequestBody Long[] ids){
        try {
            shopService.patchDel(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }


    }







